package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueInfoVO;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueTrackRecordMapper clueTrackRecordMapper;

    @Autowired
    private TbClueMapper clueMapper;


    @Override
    public Boolean add(ClueTrackRecordVo tbClueTrackRecord) {


        tbClueTrackRecord.setCreateBy(SecurityUtils.getUsername());
        tbClueTrackRecord.setCreateTime(DateUtils.getNowDate());

        int rows01 = clueTrackRecordMapper.add(tbClueTrackRecord);

        ClueInfoVO clue = new ClueInfoVO();
        BeanUtils.copyProperties(tbClueTrackRecord,clue);
        clue.setCreateBy(SecurityUtils.getUsername());
        clue.setCreateTime(DateUtils.getNowDate());

        clue.setStatus(TbClue.StatusType.FOLLOWING.getValue()); //进行中
        clue.setId(tbClueTrackRecord.getClueId());
        int rows02 = clueMapper.updateTbClue(clue);
        return rows01>0&&rows02>0;
    }

    @Override
    public List<TbClueTrackRecord> list(Long clueId) {
        return clueTrackRecordMapper.list(clueId);
    }
}
